<template>
  <el-dialog
    title="发送系统通知"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
      <el-form-item label="接收人类型" prop="geterType">
        <el-select v-model="dataForm.geterType"  placeholder="请选择接受人类型">
          <el-option
            v-for="item in geterTypeList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="消息标题" prop="messageTile">
        <el-input v-model="dataForm.messageTile" placeholder="消息标题"></el-input>
      </el-form-item>
      <el-form-item label="消息内容" prop="messageContent">
        <el-input v-model="dataForm.messageContent" type="textarea" :rows="4" placeholder="消息内容"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            messageTile: '',
            messageContent: '',
            senter: '',
            geterType: 'MS1'},
          dataRule: {
            messageTile: [
              {required: true, message: '标题不能为空', trigger: 'blur'}
            ],
            geterType: [
              {required: true, message: '接收人类型不能为空', trigger: 'blur'}
            ],
            messageContent: [
              {required: true, message: '消息内容不能为空', trigger: 'blur'}
            ]
          },
          geterTypeList: [{'label': '学生消息', 'value': 'MS1'},
            {'label': '老师消息', 'value': 'MS2'}]
        }
      },
      methods: {
        init () {
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
          })
        },
        // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm']
            .validate((valid) => {
              if (valid) {
                this.$http({
                  url: `/sys/message/sendSysMessage`,
                  method: 'post',
                  data: this.dataForm
                }).then(({data}) => {
                  if (data && data.code === 0) {
                    this.$message({
                      message: '操作成功',
                      type: 'success',
                      duration: 1500
                    })
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              }
            })
        }
      }
    }
</script>

<style scoped>

</style>
